﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class Control_Title_Img : System.Web.UI.UserControl
{
    MODEL.News MN = new MODEL.News();
    MODEL.News _MN = new MODEL.News();
    MODEL.INews MIN = new MODEL.INews();
    MODEL.INews _MIN = new MODEL.INews();

    BLL.News BN = new BLL.News();
    BLL.INews BIN = new BLL.INews();

    protected void Page_Load(object sender, EventArgs e)
    {
        ImgURLInit();
    }


    #region ImgURLInit
    protected void ImgURLInit()
    {
        try
        {
            string RawURL = Request.RawUrl;

            if ((RawURL.Contains("News.") && !RawURL.Contains("INews."))
                || (RawURL.Contains("NewsInfo.") && !RawURL.Contains("INewsInfo.")))
            {
                #region News

                string NewsClassID;

                if (Request.QueryString["ClassID"] != null)
                {
                    NewsClassID = Request.QueryString["ClassID"].ToString();

                    if (File.Exists(Server.MapPath("~/") + "Control/img/News" + NewsClassID + ".jpg"))
                    {
                        IMG_ImgTitle.ImageUrl = "~/Control/img/News" + NewsClassID + ".jpg";
                    }
                    else if (File.Exists(Server.MapPath("~/") + "Control/img/News" + NewsClassID + ".gif"))
                    {
                        IMG_ImgTitle.ImageUrl = "~/Control/img/News" + NewsClassID + ".gif";
                    }
                    else
                    {
                        throw new Exception("无法找到图像文件，参数名\"News_" + NewsClassID + "\"");
                    }
                }
                else if (Request.QueryString["NewsID"] != null)
                {
                    MN.News_ID = Convert.ToInt32(Request.QueryString["NewsID"]);

                    _MN = BN.GetDataByID(MN);

                    NewsClassID = _MN.News_ClassID.ToString();

                    if (File.Exists(Server.MapPath("~/") + "Control/img/News" + NewsClassID + ".jpg"))
                    {
                        IMG_ImgTitle.ImageUrl = "~/Control/img/News" + NewsClassID + ".jpg";
                    }
                    else if (File.Exists(Server.MapPath("~/") + "Control/img/News" + NewsClassID + ".gif"))
                    {
                        IMG_ImgTitle.ImageUrl = "~/Control/img/News" + NewsClassID + ".gif";
                    }
                    else
                    {
                        throw new Exception("无法找到图像文件，参数名\"News_" + NewsClassID + "\"");
                    }
                }
                else
                {
                    if (File.Exists(Server.MapPath("~/") + "Control/img/News.jpg"))
                    {
                        IMG_ImgTitle.ImageUrl = "~/Control/img/News.jpg";
                    }
                    else if (File.Exists(Server.MapPath("~/") + "Control/img/News.gif"))
                    {
                        IMG_ImgTitle.ImageUrl = "~/Control/img/News.gif";
                    }
                    else
                    {
                        throw new Exception("无法找到图像文件，参数名\"News\"");
                    }
                }
                #endregion
            }
            else if (RawURL.Contains("Product.") || RawURL.Contains("ProductInfo."))
            {
                #region Product
                if (File.Exists(Server.MapPath("~/") + "Control/img/Product.jpg"))
                {
                    IMG_ImgTitle.ImageUrl = "~/Control/img/Product.jpg";
                }
                else if (File.Exists(Server.MapPath("~/") + "Control/img/Product.gif"))
                {
                    IMG_ImgTitle.ImageUrl = "~/Control/img/Product.gif";
                }
                else
                {
                    throw new Exception("无法找到图像文件，参数名\"Product\"");
                }
                #endregion
            }
            else if (RawURL.Contains("INews.") || RawURL.Contains("INewsInfo."))
            {
                #region INews

                string INewsClassID;

                if (Request.QueryString["ClassID"] != null)
                {
                    INewsClassID = Request.QueryString["ClassID"].ToString();

                    if (File.Exists(Server.MapPath("~/") + "Control/img/INews" + INewsClassID + ".jpg"))
                    {
                        IMG_ImgTitle.ImageUrl = "~/Control/img/INews" + INewsClassID + ".jpg";
                    }
                    else if (File.Exists(Server.MapPath("~/") + "Control/img/INews" + INewsClassID + ".gif"))
                    {
                        IMG_ImgTitle.ImageUrl = "~/Control/img/INews" + INewsClassID + ".gif";
                    }
                    else
                    {
                        throw new Exception("无法找到图像文件，参数名\"INews_" + INewsClassID + "\"");
                    }
                }
                else if (Request.QueryString["INewsID"] != null)
                {
                    MIN.IN_ID = Convert.ToInt32(Request.QueryString["INewsID"]);

                    _MIN = BIN.GetDataByID(MIN);

                    INewsClassID = _MIN.IN_ClassID.ToString();

                    if (File.Exists(Server.MapPath("~/") + "Control/img/INews" + INewsClassID + ".jpg"))
                    {
                        IMG_ImgTitle.ImageUrl = "~/Control/img/INews" + INewsClassID + ".jpg";
                    }
                    else if (File.Exists(Server.MapPath("~/") + "Control/img/INews" + INewsClassID + ".gif"))
                    {
                        IMG_ImgTitle.ImageUrl = "~/Control/img/INews" + INewsClassID + ".gif";
                    }
                    else
                    {
                        throw new Exception("无法找到图像文件，参数名\"INews_" + INewsClassID + "\"");
                    }
                }
                else
                {
                    if (File.Exists(Server.MapPath("~/") + "Control/img/INews.jpg"))
                    {
                        IMG_ImgTitle.ImageUrl = "~/Control/img/INews.jpg";
                    }
                    else if (File.Exists(Server.MapPath("~/") + "Control/img/INews.gif"))
                    {
                        IMG_ImgTitle.ImageUrl = "~/Control/img/INews.gif";
                    }
                    else
                    {
                        throw new Exception("无法找到图像文件，参数名\"INews\"");
                    }
                }
                #endregion
            }
            else if (RawURL.Contains("GBook."))
            {
                #region GBook
                if (File.Exists(Server.MapPath("~/") + "Control/img/GBook.jpg"))
                {
                    IMG_ImgTitle.ImageUrl = "~/Control/img/GBook.jpg";
                }
                else if (File.Exists(Server.MapPath("~/") + "Control/img/GBook.gif"))
                {
                    IMG_ImgTitle.ImageUrl = "~/Control/img/GBook.gif";
                }
                else
                {
                    throw new Exception("无法找到图像文件，参数名\"GBook\"");
                }
                #endregion
            }
            else if (RawURL.Contains("WebInfo."))
            {
                #region WebInfo

                string WebInfoID = Request.QueryString["WebInfoID"].ToString();

                if (File.Exists(Server.MapPath("~/") + "Control/img/" + WebInfoID + ".jpg"))
                {
                    IMG_ImgTitle.ImageUrl = "~/Control/img/" + WebInfoID + ".jpg";
                }
                else if (File.Exists(Server.MapPath("~/") + "Control/img/" + WebInfoID + ".gif"))
                {
                    IMG_ImgTitle.ImageUrl = "~/Control/img/" + WebInfoID + ".gif";
                }
                else
                {
                    throw new Exception("无法找到图像文件，参数名\"WebInfo_" + WebInfoID + "\"");
                }
                
                #endregion
            }
            else if (RawURL.Contains("Default.") || RawURL.Contains("Index."))
            {
                #region Default
                IMG_ImgTitle.Visible = false;
                #endregion
            }
            else
            {
                IMG_ImgTitle.Visible = false;
            }

        }
        catch (Exception ex)
        {
            LB_ImgTitle.Text = ex.Message;
        }
    }
    #endregion
}
